package com.xcexample.electronicclasscard.main

import android.app.ActionBar.LayoutParams
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import com.xcexample.electronicclasscard.databinding.LayoutUpdateBinding


class UpdateFragment() : DialogFragment() {

    private var _binding: LayoutUpdateBinding? = null
    private val TAG = "DoorFragment"

    var remoteVersion=""
    var localVersion=""
    var describe=""

    private val binding get() = _binding!!
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
    ): View {
        _binding = LayoutUpdateBinding.inflate(inflater, container, false)
        return binding.root

    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        this.dialog?.setCanceledOnTouchOutside(false)
        binding.tvCancel.setOnClickListener {
            dismiss()
        }


        binding.tvTip.text="当前版本：${localVersion}\n最新版本：${remoteVersion}\n更新内容：${describe}"


    }


    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }


    override fun onStart() {
        super.onStart()
        val displayMetrics = DisplayMetrics()
        activity?.windowManager?.defaultDisplay?.getMetrics(displayMetrics)
        val width = displayMetrics.widthPixels * 0.5
        dialog?.window?.setLayout(width.toInt(), LayoutParams.WRAP_CONTENT)
    }

}